// https://leetcode-cn.com/problems/min-stack/
// 155. 最小栈
// 设计一个支持 push, pop, top 操作，并能在常数时间内检索到最小元素的栈
class MinStack {
    _datas: number[];
    _mins: number[];

    constructor() {
        this._datas = [];
        this._mins = [Infinity];
    }

    push(val: number): void {
        this._datas.push(val);

        const min = Math.min(val, tail(this._mins));
        this._mins.push(min);
    }

    pop(): void {
        this._datas.pop();
        this._mins.pop();
    }

    top(): number {
        return tail(this._datas);
    }

    getMin(): number {
        return tail(this._mins);
    }
}

function tail(arr: number[]): number {
    return arr[arr.length - 1];
}
